package jp.co.baka.gae.example.service;

import jp.co.baka.gae.example.meta.BbsMessageMeta;
import jp.co.baka.gae.example.model.BbsMessage;

import org.slim3.datastore.Datastore;


public class BbsService {

    private static boolean idInitFlg = false;
    private static Long nextId;

    public static Long getNextId(){


        if(idInitFlg==false){
            BbsMessageMeta bbsMeta = new BbsMessageMeta();
            BbsMessage maxRec = Datastore.query(bbsMeta).sort(bbsMeta.id.desc).limit(1).asSingle();
            if(maxRec!=null){
                nextId = maxRec.getId();
            }else{
                nextId= 0L;
            }

            idInitFlg=true;
        }
        nextId++;
        return nextId;
    }






}